<?php
defined('BASEPATH') OR exit('No direct script access allowed');

//会员信息
class Member extends MY_Controller {

	function __construct(){
		parent::__construct();
		
	}	

	//start
	/**
	* @name 获取我的会员
	* @param keyword false char 姓名
	
	* @param cid false char 课程ID
	* @param page ture char 页
	* @param size false char 数据条数
	* @return 返回数据列表
	*/
	//end
	function get_list(){
		$user_id = $this->user_id;
		
		$page = $this->input->post('page',null,1);
		$size = $this->input->post('size',null,10);
		
		$arr = array(
			'keyword'=>trim($this->input->post('keyword',null,'')),
			//'mobile'=>trim($this->input->post('mobile',null,'')),
			'cid'=>trim($this->input->post('cid',null,0)),
		);
		

		$this->load->model('User/MemberModel','Member');
		$res = $this->Member->get_list($arr,$page,$size);
		
		$arr = array('list'=>$res['list'],
					 'count'=>$res['count'],
					 'page'=>$page,
					 'size'=>$size,
				);
		$this->data_out($arr);
	}
	
	//start
	/**
	* @name 获取会员信息
	* @param uid ture int 会员ID
	* @return 返回数据列表
	*/
	//end
	function get_info(){
		$user_id = $this->user_id;
		
		$uid = $this->input->post('uid',null,0);
		
		$this->load->model('User/MemberModel','Member');
		$row = $this->Member->id_get_info($uid);
		
		if(!$row){
			$this->err_out('没有该会员');
		}
		
		unset($row['openid']);
		$row['addtime'] = date('Y-m-d H:i:s',$row['addtime']);
		$this->data_out($row);
	}
	
	
	//start
	/**
	* @name 查找会员
	* @param keyword false char 姓名
	* @param mobile false char 手机号码
	* @param page ture char 页
	* @param size false char 数据条数
	* @return 返回数据列表
	*/
	//end
	function query_memeber_list(){
		
		$user_id = $this->user_id;
		
		$page = $this->input->post('page',null,1);
		$size = $this->input->post('size',null,10);
		
		$arr = array(
			'keyword'=>trim($this->input->post('keyword',null,'')),
			'mobile'=>trim($this->input->post('mobile',null,'')),
		);
		
		
		$this->load->model('Yuyue/CourseModel','Course');
		
		
		$course_list = $this->Course->get_list($this->_user['shop_id'],$user_id);
		
		$ids = array();
		foreach($course_list as $val){
			$ids[] = $val['id'];
		}

		
		$this->load->model('User/MemberModel','Member');
		$res = $this->Member->get_list($arr,$page,$size);
		
		$data = array('list'=>$res['list'],
					 'count'=>$res['count'],
					 'page'=>$page,
					 'size'=>$size,
				);
		$this->data_out($data);
	}
	
	//start
	/**
	* @name 获取会员卡列表
	* @param uid true int 用户id
	* @param cid true int 课程id
	* @return 返回数据列表
	*/
	//end
	function get_card_list(){
		$user_id = $this->user_id;
		$uid = $this->input->post('uid',null,0);
		$cid = $this->input->post('cid',null,0);
		
		
		$this->load->model('User/MemberCardModel','ucard');
		
		$list = $this->ucard->get_list($uid,$cid);
		
		
		$this->data_out($list);
	}
	
	//start
	/**
	* @name 获取会员卡信息
	* @param card_id true int 卡ID
	* @return 返回数据列表
	*/
	//end
	function get_card_info(){
		$user_id = $this->user_id;
		$card_id = $this->input->post('card_id',null,0);
		
		$this->load->model('User/MemberCardModel','ucard');
		
		$info = $this->ucard->get_info($card_id);
		if(!$info){
			$this->err_out('会员卡不存在');
		}
		
		$this->data_out($info);
	}
	
}
